package com.neuedu.web;

import com.neuedu.pojo.PoorFamily;
import com.neuedu.pojo.Result;
import com.neuedu.service.PoorFamilyService;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.PostConstruct;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/poorFamily")
@Tag(name = "贫困户管理")
public class PoorFamilyController {
    @Resource
    private PoorFamilyService poorFamilyService;
    /**
     * 根据id查询
     * @param id
     * @return
     */
    @GetMapping("/id")
    public Result<PoorFamily> getPoorFamilyById(Integer id) {
        return this.poorFamilyService.getPoorFamilyById(id);
    }

    /**
     * 分页和条件查询
     * @param currentPage
     * @param pageSize
     * @param headName
     * @param idCard
     * @return
     */
    @GetMapping("/getPoorFamily")
    public Result<List<PoorFamily>> getPoorFamily(
            @RequestParam(name = "currentPage",defaultValue = "1")Integer currentPage,
            @RequestParam(name = "pageSize",defaultValue = "10")Integer pageSize,
            @RequestParam(name = "headName",defaultValue = "")String headName,
            @RequestParam(name ="belongArea",defaultValue = "")String belongArea,
            @RequestParam(name = "idCard",defaultValue = "")String idCard) {
        return this.poorFamilyService.getPoorFamily(currentPage,pageSize,headName,idCard,belongArea);
    }

    /**
     * 添加
     */
    @PostMapping("/addPoorFamily")
    public Result<Void> addPoorFamily(@RequestBody PoorFamily poorFamily) {
        return this.poorFamilyService.addPoorFamily(poorFamily);
    }

    /**
     * 修改
     */
    @PutMapping("/updatePoorFamily")
    public Result<Void> updatePoorFamily(@RequestBody PoorFamily poorFamily) {
        return this.poorFamilyService.updatePoorFamily(poorFamily);
    }

    /**
     * 删除
     */
    @DeleteMapping("deletePoorFamily/{id}")
    public Result<Void> deletePoorFamily(@PathVariable("id") Integer id) {
        return this.poorFamilyService.deletePoorFamily(id);
    }

}
